#!/usr/bin/env python

#retrieves undeleted notes from the iphone image dump

import sqlite3

from time import strftime, localtime, gmtime
def run(s):
	#check if the file notes.sqlite is there
	try:
		print('Found "{}"'.format(s))
		#connect to the db

		conn = sqlite3.connect(s)
		c = conn.cursor()
		#print the column headers

		#get the table to print
		for creation_Date,modification_Date, title, content in c.execute('select ZCREATIONDATE,ZMODIFICATIONDATE, ZTITLE, ZCONTENT from ZNOTE, ZNOTEBODY where ZNOTEBODY.Z_PK = ZNOTE.Z_PK'):
			

			creationTime = strftime('%Y-%m-%d %H:%M:%S (%Z)', localtime(creation_Date+978307200))
			modificationTime = strftime('%Y-%m-%d %H:%M:%S (%Z)', localtime(modification_Date+978307200))
			#prints the values
			print('{0:30}{1:30}{2:50}{3:50}'.format(creationTime,modificationTime, title, content))

		#endofloop
			
	except sqlite3.Error:
		print('The notes.db is not placed in the current working directory')    

	

def main():
	#execute the operation on the sms.db file
	
	databaseName = 'notes.sqlite'
	run(databaseName)

#exec main
if __name__ == '__main__':
	main()